package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.admin.vo.graph.GraphVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.entity.GraphInfo;
import com.atguigu.lease.web.admin.service.GraphInfoService;
import com.atguigu.lease.web.admin.mapper.GraphInfoMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
* @author liubo
* @description 针对表【graph_info(图片信息表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class GraphInfoServiceImpl extends ServiceImpl<GraphInfoMapper, GraphInfo>
    implements GraphInfoService{

    @Override
    public void insertByGraphVoAndItem(ItemType itemType,Long itemId, List<GraphVo> graphVos) {
        if (!CollectionUtils.isEmpty(graphVos)) {
            List<GraphInfo> graphInfos = new ArrayList<>();
            for (GraphVo item : graphVos) {
                GraphInfo graphInfo = new GraphInfo();
                graphInfo.setName(item.getName());
                graphInfo.setUrl(item.getUrl());
                graphInfo.setItemType(itemType);
                graphInfo.setItemId(itemId);
                graphInfos.add(graphInfo);
            }
            this.saveBatch(graphInfos);
        }
    }
}




